/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package factory;

import java.util.ArrayList;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;

/**
 *
 * @author raul
 */
public class NauEnemiga0 extends NauBase {

    boolean enemigo = true;
    Timer timer;
    aux a;
    Shoot msE = null;
    NauBase nbE = null;
    ArrayList<shootE> sbe = new ArrayList<shootE>();

    public NauEnemiga0(float vida, float vidaT, shootE shoot, Image nau, float posX, float posY, Image nauDestroy) {
        super(vida, vidaT, shoot, nau, posX, posY, nauDestroy);
        super.posX = posX;
        super.posY = posY;
        System.out.println("hola soy una nave enemiga");
    }

    @Override
    public void setLocation(float posX, float posY) {
        super.setLocation(posX, posY);
        super.shape = new Rectangle(posX, posY, nau.getWidth(), nau.getHeight());
    }

    @Override
    public void render(GameContainer gc, Graphics g) {
        g.drawImage(nau, posX, posY);
        for (shootE n : sbe) {
            if (n != null) {
                n.render(gc, g);
            }
        }
    }

    public void update(int delta) throws SlickException {
        if (!(posY <= 650)) {
            posY = -11;
            posX = 1000;
            destroy = true;
            System.out.println("ya no estoy");
        } else {
            posY += 2;
            shape.setLocation(posX, posY);

            timer = new Timer(300, new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    msE = shoot.copiarShoot();
                    msE.setLocation(posX + 58, posY + 100);
                    //a.posShootE(nbE.getPosX() + 58, nbE.getPosY() + 100, (shootE) msE);
                    sbe.add((shootE) msE);
                    if (600 <= getPosY()) {
                        timer.stop();
                    }
                }
            });
        }
        updateshoot(delta);

    }

    public void updateshoot(int delta) {

        timer.start();
        for (shootE n : sbe) {
            if (n != null) {
                n.update(delta);
            }
        }
    }
}
